package com.hnx.admin.factory;

import com.hnx.admin.api.log.LogHandler;
import com.hnx.admin.enums.logs.LogType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/*
项目名称： core
创 建 人: 倔强的头发
创建日期： 2025/6/9   9:47:15 
描   述：
*/
@Component
public class LogHandlerFactory {
    private final Map<LogType, LogHandler<?>> handlerMap = new ConcurrentHashMap<>();
    @Autowired
    public LogHandlerFactory(List<LogHandler<?>> handlers) {
        handlers.forEach(handler ->
                handlerMap.put(handler.getLogType(), handler)
        );
    }
    @SuppressWarnings("unchecked")
    public <T> LogHandler<T> getHandler(LogType logType) {
        return (LogHandler<T>) handlerMap.get(logType);
    }
}
